package com.fqr;

import java.util.ArrayList;
import java.util.List;

public class EmailErrorHandler extends BaseErrorHandler {
	
	private String subject;
	private String fromAddress;
	private List<String> toAddress = new ArrayList<String>();

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getFromAddress() {
		return fromAddress;
	}

	public void setFromAddress(String fromAddress) {
		this.fromAddress = fromAddress;
	}

	public List<String> getToAddress() {
		return toAddress;
	}

	public void setToAddress(List<String> toAddress) {
		this.toAddress = toAddress;
	}

	public void handle(String jobName, Exception e) {
		String sub = subject;
		if(sub == null || sub.trim().length() == 0)
			sub = "Error - " + jobName;
		
		StringBuffer msg = new StringBuffer("");
		extractCause(msg, e);
		
		EmailInfo emailObject = new EmailInfo();
		emailObject.setEmailfromAdd(fromAddress);
		emailObject.setEmailrecAdd(toAddress);
		emailObject.setEmailSubject(sub );
		emailObject.setEmailMessage(msg.toString());

		EmailUtil emailUtil = new EmailUtil();
		emailUtil.sendEmail(emailObject);		
	}

}
